package ar.com.spsolutions.splibrary.examplebd;

import ar.com.spsolutions.splibrary.author.Author;
import ar.com.spsolutions.splibrary.book.Book;
import ar.com.spsolutions.splibrary.book.BookCopy;
import ar.com.spsolutions.splibrary.book.category.Category;
import ar.com.spsolutions.splibrary.notifiers.MockNotifier;
import ar.com.spsolutions.splibrary.services.AuthorService;
import ar.com.spsolutions.splibrary.services.BookService;
import ar.com.spsolutions.splibrary.services.EntityService;
import ar.com.spsolutions.splibrary.user.User;
import ar.com.spsolutions.splibrary.user.role.UserRole;

public class BookBD {

    private static final String IMGLIBROX = "bookPic/Libro X.jpg";

    private static final String COMENTARIO = "Este libro, lejos de hablar de las X, contiene informacion valiosa sobre ese extranio y apacionante simbolo. La X!";

    private static final String EDITORIAL = "EditX";

    private static final String ISBN = "77012340";

    private BookBD() {
        //
    }

    public static BookCopy bookBD(final EntityService entityService, final AuthorService authorService) {
        // BookRepository br = new BookRepository();

        final Author author = BookBD.getAuthor(authorService);

        final Author author1 = BookBD.getAuthor1(authorService);

        final BookService bs = entityService.getBookService();
        BookBD.getBook(bs, author);

        BookBD.getBook1(bs, author1, entityService);

        BookBD.getBook2(bs, author);

        BookBD.getBook3(bs, author);

        final Book book4 = BookBD.getBook4(bs, author);

        BookBD.getBook5(bs, author, book4);

        return BookBD.getBook6(bs, author);

    }

    private static BookCopy getBook6(final BookService bookService, final Author author) {
        final Book book6 = new Book(null);
        book6.setIsbn(BookBD.ISBN);
        book6.setTitle("Libro X6");
        book6.setAuthor(author);
        book6.setPublisher(BookBD.EDITORIAL);
        book6.setDescription(BookBD.COMENTARIO);
        book6.addOneStar();
        book6.createCopies(30);
        book6.setPic(BookBD.IMGLIBROX);
        bookService.add(book6);
        return book6.getACopy();
    }

    private static void getBook5(final BookService bookService, final Author author, final Book book4) {
        final Book book5 = new Book(null);
        book5.setIsbn(BookBD.ISBN);
        book5.setTitle("Libro X5");
        book5.setAuthor(author);
        book5.setPublisher(BookBD.EDITORIAL);
        book5.setDescription(BookBD.COMENTARIO);
        book4.addOneStar();
        book5.createCopies(30);
        book5.setPic(BookBD.IMGLIBROX);
        bookService.add(book5);
    }

    private static Book getBook4(final BookService bookService, final Author author) {
        final Book book4 = new Book(null);
        book4.setIsbn(BookBD.ISBN);
        book4.setTitle("Libro X4");
        book4.setAuthor(author);
        book4.setPublisher(BookBD.EDITORIAL);
        book4.setDescription(BookBD.COMENTARIO);
        book4.addThreeStar();
        book4.createCopies(30);
        book4.setPic(BookBD.IMGLIBROX);
        bookService.add(book4);
        return book4;
    }

    private static void getBook3(final BookService bookService, final Author author) {
        final Book book3 = new Book(null);
        book3.setIsbn(BookBD.ISBN);
        book3.setTitle("Libro X3");
        book3.setAuthor(author);
        book3.setPublisher(BookBD.EDITORIAL);
        book3.setDescription(BookBD.COMENTARIO);
        book3.addTwoStar();
        book3.createCopies(30);
        book3.setPic(BookBD.IMGLIBROX);
        bookService.add(book3);
    }

    private static void getBook1(final BookService bookService, final Author author1, final EntityService entityService) {
        final Book book1 = new Book(new MockNotifier());
        book1.setIsbn("9780553382563");
        book1.setTitle("I, Robot");
        book1.setAuthor(author1);
        book1.setPublisher("Spectra ");
        book1.setDescription("The three laws of Robotics:\n"
                + "1) A robot may not injure a human being or, through inaction, allow a human being to come to harm\n"
                + "2) A robot must obey orders givein to it by human beings except where such orders would conflict with the First Law.\n"
                + "3) A robot must protect its own existence as long as such protection does not conflict with the First or Second Law.\n"
                + "With these three, simple directives, Isaac Asimov changed our perception of robots forever when he formulated the laws governing their behavior.\n"
                + "In I, Robot, Asimov chronicles the development of the robot through a series of interlinked stories: from its primitive origins in the present to its ultimate perfection\n"
                + "in the not-so-distant future--a future in which humanity itself may be rendered obsolete.\n"
                + "Here are stories of robots gone mad, of mind-read robots, and robots with a sense of humor. Of robot politicians, and robots who secretly run the world--all\n"
                + "told with the dramatic blend of science fact and science fiction that has become Asmiov's trademark.");
        book1.addFiveStar();
        // book1.createCopies(1);
        final User u1 = new User();
        u1.setName("u1");
        u1.setPassword("123456");
        u1.setEmail("valandil.ti@gmail.com");
        u1.setRole(UserRole.customer());
        entityService.getUserService().add(u1);
        book1.reservedFor(u1);
        book1.setPic("bookPic/I, Robot.jpg");
        book1.addCategory(new Category("ficcion"));
        book1.addCategory(new Category("terror"));
        bookService.add(book1);
    }

    private static void getBook2(final BookService bookService, final Author author) {
        final Book book2 = new Book(null);
        book2.setIsbn(BookBD.ISBN);
        book2.setTitle("Libro X2");
        book2.setAuthor(author);
        book2.setPublisher(BookBD.EDITORIAL);
        book2.setDescription(BookBD.COMENTARIO);
        book2.addFourStar();
        book2.createCopies(30);
        book2.setPic(BookBD.IMGLIBROX);
        bookService.add(book2);
    }

    private static void getBook(final BookService bookService, final Author author) {
        final Book book = new Book(null);
        book.setIsbn(BookBD.ISBN);
        book.setTitle("Libro X");
        book.setAuthor(author);
        book.setPublisher(BookBD.EDITORIAL);
        book.setDescription(BookBD.COMENTARIO);
        // book.setPic(pic);
        book.addTwoStar();
        book.createCopies(30);
        book.setPic(BookBD.IMGLIBROX);
        final User user = new User();
        user.setName("Usuario");
        book.addComment(user, "el comentario mas largo de todos");
        bookService.add(book);
    }

    private static Author getAuthor1(final AuthorService authorService) {
        final Author author1 = new Author();
        author1.setName("Isaac Asimov");
        authorService.add(author1);
        return author1;
    }

    private static Author getAuthor(final AuthorService authorService) {
        final Author author = new Author();
        author.setName("Senior X");
        authorService.add(author);
        return author;
    }
}
